﻿using System;
using System.Linq;
using System.Text;


namespace practice
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("欢迎玩猜数小游戏");
                Console.WriteLine("1.简单");
                Console.WriteLine("2.困难");
                Console.WriteLine("3.超难");
                Console.Write("请输入你要进行的游戏等级:");
                int lv = ReadInt();

                switch (lv)
                {
                    case 1:
                        //简单
                        guessingNumber(10);
                        break;
                    case 2:
                        //困难
                        guessingNumber(100);
                        break;
                    case 3:
                        //超难
                        guessingNumber(1000);
                        break;
                }

                Console.Write("是否再次玩: ");
                string isPlay = Console.ReadLine();
                if (isPlay.Equals("否"))
                {
                    Console.WriteLine("退出游戏");
                    break;
                }
            }
        }

        private static void guessingNumber(int v)
        {
            Random random = new Random();
            int randomNumber = random.Next(1, v);
            int i;
            for (i = 0; i < Convert.ToInt32(v / 3); i++)
            {
                Console.Write("请输入你猜的数字: ");
                int playerNumber = ReadInt();
                if (playerNumber > randomNumber)
                {
                    Console.WriteLine("你猜大了!");
                }
                else if (playerNumber < randomNumber)
                {
                    Console.WriteLine("你猜小了!");
                }
                else
                {
                    Console.WriteLine("恭喜你猜中了!");
                    break;
                }
            }
            if(i == Convert.ToInt32(v / 3)){
                Console.WriteLine("你失败了");
            }
        }

        private static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }
    }
}
